package ce.com.newbluedemo.my;

import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;


import java.util.ArrayList;

import ce.com.cenewbluesdk.CEBC;
import ce.com.cenewbluesdk.entity.k3.Send_Alarm_Info_Struct_K3;
import ce.com.cenewbluesdk.proxy.BleFactory;
import ce.com.cenewbluesdk.proxy.CEDevK3Proxy;
import ce.com.newbluedemo.R;

/**
 * Created by Administrator on 2016/11/15 0015.
 */
public class TestBlueActivity extends MyActivity implements View.OnClickListener {
    private TextView blue_state;

    private CEDevK3Proxy k3Proxy;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.acitivty_test);
        k3Proxy = BleFactory.getInstance().getK3Proxy();
        blue_state = (TextView) findViewById(R.id.blue_state);
        if (k3Proxy.isConnectOK()) {
            blue_state.setText("蓝牙连接成功");
        } else {
            blue_state.setText("蓝牙连接失败");
        }


        findViewById(R.id.send_time).setOnClickListener(this);
        findViewById(R.id.send_alarm).setOnClickListener(this);
        findViewById(R.id.send_userinfo).setOnClickListener(this);
        findViewById(R.id.get_devinfo).setOnClickListener(this);
        findViewById(R.id.send_gs).setOnClickListener(this);


    }

    @Override
    public void receiveData(Message message) {
        if (message.what == CEBC.BLUE_CONNECT_STATE_CHANGE) {
            String s = "";
            if (message.arg1 == CEBC.BLUE_CONNECTED) {
                s = "蓝牙连接成功";
            } else if (message.arg1 == CEBC.BLUE_CONNECTING) {
                s = "蓝牙正在连接";
            } else if (message.arg1 == CEBC.BLUE_DISCONNECT) {
                s = "蓝牙连接失败";
            }
            blue_state.setText(s);
        }
    }

    @Override
    public void onClick(View v) {
        if (!k3Proxy.isConnectOK()) {
            Toast.makeText(this, "蓝牙已经断开", Toast.LENGTH_SHORT);
            return;
        }
        switch (v.getId()) {
            case R.id.send_time:
                k3Proxy.getSendHelper().sendTime();
                break;
            case R.id.send_gs:

                k3Proxy.getSendHelper().setEnableGsDataTrans(true);
                break;
            case R.id.send_userinfo:
                k3Proxy.getSendHelper().sendUserInfo(1000, 0, 20, 170, 50, 1);
                break;

            case R.id.send_alarm:
                Send_Alarm_Info_Struct_K3 alarm = new Send_Alarm_Info_Struct_K3((byte) 1, (byte) 11, (byte) 12, (byte) 1);
                Send_Alarm_Info_Struct_K3 alarm1 = new Send_Alarm_Info_Struct_K3((byte) 2, (byte) 12, (byte) 13, (byte) 0);
                Send_Alarm_Info_Struct_K3 alarm2 = new Send_Alarm_Info_Struct_K3((byte) 3, (byte) 13, (byte) 14, (byte) 1);
//                Send_Alarm_Info_Struct_K3  alarm3=new Send_Alarm_Info_Struct_K3((byte)4,(byte)14,(byte)16,(byte)0);
//                Send_Alarm_Info_Struct_K3  alarm5=new Send_Alarm_Info_Struct_K3((byte)5,(byte)16,(byte)17,(byte)1);
                ArrayList<Send_Alarm_Info_Struct_K3> k3s = new ArrayList<>();
                k3s.add(alarm);
                k3s.add(alarm1);
                k3s.add(alarm2);
//                k3s.add(alarm3);
//                k3s.add(alarm5);

                k3Proxy.getSendHelper().sendAlarmInfo(k3s);
                break;
            case R.id.get_devinfo:
                k3Proxy.getSendHelper().getMixInfo();
                break;
        }
    }
}
